﻿Imports System.Data.SqlClient

Public Class frmFormularios
    Dim F As New clsFormularios

    Private Sub frmFormularios_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolStrip1.Cursor = Cursors.Hand
        ToolStrip1.RenderMode = System.Windows.Forms.ToolStripRenderMode.System
        ToolStrip1.Stretch = True

        Me.dgDatos.DefaultCellStyle.Font = New Font("Arial", 8, FontStyle.Regular)
        muestraForms()

    End Sub
    Sub muestraForms()
        dgDatos.Rows.Clear()

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = InitialConnection

        Dim cmdBuscar As New SqlCommand
        cmdBuscar.Connection = cnConn
        cmdBuscar.CommandText = "Select * from Formularios Order by Familia"
        Dim rdBuscar As SqlDataReader
        cnConn.Open()
        rdBuscar = cmdBuscar.ExecuteReader

        Do While rdBuscar.Read()
            dgDatos.Rows.Add(rdBuscar("idFormulario"), rdBuscar("Nombre").ToString.Trim, rdBuscar("tipo").ToString.Trim, rdBuscar("Formulario").ToString.Trim, rdBuscar("Familia").ToString.Trim, rdBuscar("Descripcion").ToString.Trim)
        Loop
    End Sub

    Private Sub toolGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolGuardar.Click
        If txtNombre.Text = "" Then
            MsgBox("Debes indicar el nombre", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If lstTipo.Text = "Seleccionar..." Then
            MsgBox("Debes indicar el tipo", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If lstTipo.Text = "" Then
            MsgBox("Debes indicar el tipo", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If txtFormulario.Text = "" Then
            MsgBox("Debes indicar el formulario", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If lstFamilia.Text = "Seleccionar..." Then
            MsgBox("Debes indicar la familia", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If lstFamilia.Text = "" Then
            MsgBox("Debes indicar la familia", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If txtDescripcion.Text = "" Then
            MsgBox("Debes indicar una descripcion", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If


        F.Nombre = txtNombre.Text.Trim
        F.Tipo = lstTipo.Text
        F.Formulario = txtFormulario.Text.Trim
        F.Familia = lstFamilia.Text
        F.Descripcion = txtDescripcion.Text.Trim
        F.Insertar()

        muestraForms()

        txtDescripcion.Clear()
        txtFormulario.Clear()
        txtNombre.Clear()
        lstFamilia.SelectedText = "Seleccionar..."
        lstTipo.SelectedText = "Seleccionar..."


    End Sub

    Private Sub btnAbrir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbrir.Click
        If txtNombre.Text = "" Then
            MsgBox("Debes indicar el nombre", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If lstTipo.Text = "Seleccionar..." Then
            MsgBox("Debes indicar el tipo", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If lstTipo.Text = "" Then
            MsgBox("Debes indicar el tipo", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If txtFormulario.Text = "" Then
            MsgBox("Debes indicar el formulario", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If lstFamilia.Text = "Seleccionar..." Then
            MsgBox("Debes indicar la familia", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If lstFamilia.Text = "" Then
            MsgBox("Debes indicar la familia", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If
        If txtDescripcion.Text = "" Then
            MsgBox("Debes indicar una descripcion", MsgBoxStyle.Exclamation, "Aviso")
            Exit Sub
        End If


        F.Nombre = txtNombre.Text.Trim
        F.Tipo = lstTipo.Text
        F.Formulario = txtFormulario.Text.Trim
        F.Familia = lstFamilia.Text
        F.Descripcion = txtDescripcion.Text.Trim
        F.Insertar()




        Close()

       
    End Sub

    Private Sub RadButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton2.Click
        txtDescripcion.Clear()
        txtFormulario.Clear()
        txtNombre.Clear()
        lstFamilia.SelectedText = "Seleccionar..."
        lstTipo.SelectedText = "Seleccionar..."
    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        ToExcel(dgDatos, "Lista de formularios")
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        
    End Sub

    Private Sub toolSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles toolSalir.Click
        Close()

    End Sub
End Class